//
//  BLMeet_Cell_DetailTips.m
//  Byelone
//
//  Created by 乔小乔 on 2020/12/17.
//

#import "BLMeet_Cell_DetailTips.h"
#define random(r, g, b, a) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:(a)/255.0]

#define randomColor random(arc4random_uniform(256), arc4random_uniform(256), arc4random_uniform(256), arc4random_uniform(256))
@implementation BLMeet_Cell_DetailTips
{
    void(^blockReload)(void);
}
- (void)awakeFromNib {
    [super awakeFromNib];
    self.viewBj.layer.cornerRadius = 6;
    [self.viewBj setShadowRadius:16 color:BL_COLOR_PURPLE_L(0.12) offset:CGSizeMake(0, 4) opacity:1];
    self.btnEnd.layer.cornerRadius = 9;
    self.btnEnd.layer.masksToBounds = YES;
    
//    CGFloat tipsViewW = self.viewTips.width;
//    _viewTips = [[BLButtonTagView alloc]initWithTotalTagsNum:30
//                                                  viewWidth:tipsViewW
//                                                    eachNum:0
//                                                    Hmargin:Hmargin_VALUE
//                                                    Vmargin:Vmargin_VALUE
//                                                  tagHeight:Tag_Height
//                                                     tagCor:Tag_Height/2
//                                                tagTextFont:[UIFont boldSystemFontOfSize:14]
//                                               tagTextColor:[UIColor chColorWithHexString:@"#6C72F5"]
//                                       selectedTagTextColor:[UIColor whiteColor]
//                                    selectedBackgroundColor:[UIColor chColorWithHexString:@"#6C72F5"]];
//    _viewTips.maxSelectNum = 10;
//
//    [self.baseViewTips addSubview:_viewTips];
//
//    _viewTips.translatesAutoresizingMaskIntoConstraints = NO;
//    NSLayoutConstraint *top = [NSLayoutConstraint constraintWithItem:_viewTips attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:_baseViewTips attribute:NSLayoutAttributeTop multiplier:1 constant:0];
    
//     NSLayoutConstraint *left = [NSLayoutConstraint constraintWithItem:_viewTips attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:_baseViewTips attribute:NSLayoutAttributeLeft multiplier:1 constant:0];
//
//
//     NSLayoutConstraint *bottom = [NSLayoutConstraint constraintWithItem:_viewTips attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:_baseViewTips attribute:NSLayoutAttributeBottom multiplier:1 constant:0];
//
//     NSLayoutConstraint *right = [NSLayoutConstraint constraintWithItem:_viewTips attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:_baseViewTips attribute:NSLayoutAttributeRight multiplier:1 constant:0];
//
//    [_baseViewTips addConstraints:@[top,left,bottom,right]];
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
- (void)reloadWithData:(NSArray *)tagArray{
    self.tagArray = tagArray;
    if(self.isShouldEdit){
        self.btnEdit.hidden = NO;
    }else{
        self.btnEdit.hidden = YES;
    }
    
    [self.viewTips.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    if (tagArray.count>0) {
        CGFloat spaceLeft = 0;
        CGFloat spaceTop = 0;
        for (int i=0; i<tagArray.count; i++) {
            NSString *str = tagArray[i];
            UIView *view = [BLCommonTool createTip:nil title:str color:randomColor point:CGPointMake(spaceLeft, spaceTop)];
            [self.viewTips addSubview:view];
            if (spaceLeft + view.frame.size.width>BL_WINDOW_WIDTH-82) {
                spaceTop = spaceTop+20;
                spaceLeft = 0;
                view.frame = CGRectMake(spaceLeft, spaceTop, view.frame.size.width, view.frame.size.height);
            }
            spaceLeft = spaceLeft + view.frame.size.width+6;
        }
        self.layoutTips.constant = spaceTop + 14+5;
    }else{
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 8, BL_WINDOW_WIDTH-82, 0)];
        label.font = [UIFont systemFontOfSize:10];
        label.textColor = [UIColor chColorWithHexString:@"#888888"];
        label.text = @"主人比较懒，什么都没有写哦~";
        [label sizeToFit];
        [self.viewTips addSubview:label];
        self.layoutTips.constant = label.frame.size.height+8;
    }
    if (blockReload) {
        blockReload();
    }
}
- (void)blockReloadContent:(void(^)(void))over{
    if (blockReload!=over) {
        blockReload = over;
    }
}

- (IBAction)clickEdit:(UIButton *)sender {
    //    101编辑,102保存
    if (sender.tag == 101) {
//        self.btnEdit.hidden = YES;
//        self.btnEnd.hidden = NO;
    }else if (sender.tag == 102){
//        self.btnEdit.hidden = NO;
//        self.btnEnd.hidden = YES;
    }
    if (self.editBlock) {
        self.editBlock(sender.tag);
    }
}

-(void)setTagArray:(NSArray *)tagArray{
    
    _tagArray = tagArray;
}


//-(CGFloat)cellHeight{
//    CGFloat tipsViewW = self.viewTips.width;
//    CGFloat height = [BLButtonTagView returnViewHeightWithTagTexts:_tagArray
//                                                 viewWidth:tipsViewW
//                                                   eachNum:0
//                                                   Hmargin:Hmargin_VALUE
//                                                   Vmargin:Vmargin_VALUE
//                                                 tagHeight:Tag_Height
//                                               tagTextFont:[UIFont systemFontOfSize:14.f]];
//    
//    return height + 22 + 34 + 14;
//}


@end
